// 数组去重，在leetcode中非常常见，积累方法
//http://www.hellojava.com/a/92242.html
//new Set
// let list = [1, 1, 'a', 'a', true, true, false, false, null, '', null, '', undefined, undefined];
// let list1 = Array.from(new Set(list)); //  [ 1, "a", true, false, null, "", undefined ]
// let list2 = [...new Set(list)]; //  [ 1, "a", true, false, null, "", undefined ]
// console.log(list1)
// console.log(list2)

var intersection = function(nums1, nums2) {
    let shortArr1 = nums1.length >= nums2.length ? nums2 : nums1;
    let longArr = nums1.length >= nums2.length ? nums1 : nums2;
    let result = [];

    //先将短数组去重
    let shortArr = [...new Set(shortArr1)] //ES6新写法，先给短的数组去重
    //再在长数组中遍历
    for(let i = 0;i < shortArr.length;i++){
        if(longArr.indexOf(shortArr[i]) >= 0){
            result.push(shortArr[i])
        }z
    }
    return result
};

console.log(intersection([2,6,2,9,1],[7,1]))
